#ifndef AGT_MATERIAL_H
#define AGT_MATERIAL_H

namespace agtk {

//Makes the image into a mipmapped texture, and returns the id of the texture
GLuint CreateTextureFromImage(Image *image);

/** Color structure.
	@author Tom savage
**/
struct Color
{
	float r;
	float g;
	float b;
	float a;

	Color(void) {
		r = 1.0f;
		g = 1.0f;
		b = 1.0f;
		a = 1.0f;
	}

	Color(float rIn, float gIn, float bIn, float aIn=1.0) {
		r = rIn;
		g = gIn;
		b = bIn;
		a = aIn;
	}
};

/** Texture structure.
	@author Tom Savage
**/
struct Texture
{
	GLuint textureId;

	Texture(const char* imagePath) {
		textureId = CreateTextureFromImage(loadBMP(imagePath));
	}

	Texture(std::string imagePath) {
		textureId = CreateTextureFromImage(loadBMP(imagePath.c_str()));
	}

	void Bind(int target) {
		glActiveTexture(GL_TEXTURE0+target);
		glBindTexture(GL_TEXTURE_2D, textureId);
	}
};

/** Material class.
	@author Tom Savage
**/
class Material : public Resource< Material >
{
public:
	Material();
	Material( char *name, char *path = "./" );
	virtual ~Material();
	void UseTextures(bool yesno);
	
	Color* diffuseColor;
	Color* falloffColor;
	Texture* diffuseMap;
	Texture* normalMap;
	Texture* specularMap;
	Texture* glowMap;
	float specularIntensity;
	float specularPower;
	float glowIntensity;
	float falloffIntensity;
	float falloffPower;
	float falloffDetail;
	std::string materialTitle;
	std::string materialDescription;
	std::string materialAuthor;

private:
	bool Load(char* fullpath);
};

}

#endif